#encoding: utf-8
'''
Created on 2012-4-9

@author: huangjacky
@copyright: TeamV - Group: WhutOJ
这个模块主要类主要是负责来自网页端的数据
'''

from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor
from pyojParserWeb import PyOJParserWeb

class PyOJTCPWeb(Protocol):
    """
    类主要用来接收网页端发送过来的数据，并解析执行
    """
    
    def __init__(self):
#        super(PyOJTCPWeb, self).__init__()
        self.__port = 5112 # 默认端口
        self.__parser = PyOJParserWeb()
        self.__factory = Factory()
        self.__factory.protocol = PyOJTCPWeb
        
        
    def dataReceived(self, data):
        # Protocol.dataReceived(self, data)
        self.__parser.parse(data)
        
    def start(self):
        """启动服务"""
        reactor.listenTCP(self.port, self.__factory)
        reactor.run()
    
    def stop(self):
        "停止服务"
        reactor.stop()

    # 属性的getter和setter部分
    def getPort(self):
        return self.__port
    
    def setPort(self, value):
        self.__port = value
        
    port = property(getPort, setPort, None, "监听的端口")
    
